import { defHttp } from '@/utils/http/axios';
import { UploadAttachment, UploadResult } from '../model/baseModel';
import { IDictList, IIndustry } from './model/indexModel';

enum Api {
  dictList = '/system/dict/data/getDataList',
  districts = '/system/districts/getListData',
  uploadApi = '/api/system/dfs/image_upload',
  industryDownList = '/system/org/industry/getDownList',
  uploadAttachment = "/api/system/dfs/upload",
}

/**
 * @description 获取服务器字典
 * @date 13/07/2022
 * @export
 * @param {string} [dictTypes] 字典key | 多个key逗号隔开
 */
export function dictList(dictTypes?: string) {
  return defHttp.get<IDictList>({
    url: Api.dictList,
    data: {
      dictTypes,
    },
  });
}

/**
 * @description 获取省市区 (未完)
 * @date 20/07/2022
 * @export
 * @param {number} [pid]
 */
export function district(pid?: number) {
  return defHttp.get({
    url: Api.districts,
    params: {
      pid,
    },
  });
}

/**
 * @description 上传文件
 * @date 20/07/2022
 * @export
 * @param {Blob} file
 */
export function uploadApi(params: { file: Blob; filename: string }) {
  return defHttp.uploadFile<UploadResult>(
    {
      url: Api.uploadApi,
    },
    {
      file: params.file,
      filename: params.filename,
    },
  );
}

/**
 * @description 上传附件
 * @date 20/07/2022
 * @export
 * @param {Blob} file
 */
export function uploadAttachment(params: { file: Blob; filename: string }) {
  return defHttp.uploadFile<UploadAttachment>(
    {
      url: Api.uploadAttachment,
    },
    {
      file: params.file,
      filename: params.filename,
    },
  );
}

/**
 * @description 行业下拉列表
 * @date 20/07/2022
 * @export
 * @param
 */
export function industryDownList() {
  return defHttp.get<IIndustry[]>({
    url: Api.industryDownList,
  });
}
